package com.tancire.web.controller.platform.system;

import com.tancire.common.annotation.Log;
import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.enums.BusinessType;
import com.tancire.common.utils.poi.ExcelUtil;
import com.tancire.system.domain.SysAddressLibrary;
import com.tancire.system.service.ISysAddressLibraryService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 地址管理Controller
 *
 * @author tancire
 * @date 2024-03-02
 */
@RestController
@RequestMapping("/system/sysAddressLibrary")
public class SysAddressLibraryController extends BaseController {

    @Resource
    private ISysAddressLibraryService sysAddressLibraryService;

    /**
     * 查询地址管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:sysAddressLibrary:list')")
    @GetMapping("/list")
    public AjaxResult list(SysAddressLibrary sysAddressLibrary) {
        List<SysAddressLibrary> list = sysAddressLibraryService.selectSysAddressLibraryList(sysAddressLibrary);
        return AjaxResult.success(list);
    }

    /**
     * 查询地址管理列表
     */
    @GetMapping("/list/cache")
    public AjaxResult listCache() {
        Object list = sysAddressLibraryService.selectAddressByRedis();
        return AjaxResult.success("查询成功", list);
    }

    /**
     * 导出地址管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:sysAddressLibrary:export')")
    @Log(title = "地址管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAddressLibrary sysAddressLibrary) {
        List<SysAddressLibrary> list = sysAddressLibraryService.selectSysAddressLibraryList(sysAddressLibrary);
        ExcelUtil<SysAddressLibrary> util = new ExcelUtil<SysAddressLibrary>(SysAddressLibrary.class);
        util.exportExcel(response, list, "地址管理数据");
    }

    /**
     * 获取地址管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:sysAddressLibrary:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(sysAddressLibraryService.selectSysAddressLibraryById(id));
    }

    /**
     * 新增地址管理
     */
    @PreAuthorize("@ss.hasPermi('system:sysAddressLibrary:add')")
    @Log(title = "地址管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAddressLibrary sysAddressLibrary) {
        return toAjax(sysAddressLibraryService.insertSysAddressLibrary(sysAddressLibrary));
    }

    /**
     * 修改地址管理
     */
    @PreAuthorize("@ss.hasPermi('system:sysAddressLibrary:edit')")
    @Log(title = "地址管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAddressLibrary sysAddressLibrary) {
        return toAjax(sysAddressLibraryService.updateSysAddressLibrary(sysAddressLibrary));
    }

    /**
     * 删除地址管理
     */
    @PreAuthorize("@ss.hasPermi('system:sysAddressLibrary:remove')")
    @Log(title = "地址管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(sysAddressLibraryService.deleteSysAddressLibraryByIds(ids));
    }
}
